<?PHP
require_once('phpcassa/connection.php');
require_once('phpcassa/columnfamily.php');

$visitors = array("1" => "111111111", "2" => "222222222", "3" => "333333333", "4" => "444444444", "5" => "555555555", "6" => "666666666", "7" => "777777777");
$servers = array("10.169.42.95:9160", "10.169.41.152:9160", "10.169.3.177:9160", "10.168.237.233:9160", "10.169.62.182:9160", "10.176.46.224:9160");
$pool = new ConnectionPool("Visitor", $servers);
$column_family = new ColumnFamily($pool, 'ExposureHistoryStandard');
//$debug="";
echo "\n";
$i=1;
while($i < 8){
	$Key = "canary:".$visitors[$i];
	try {
		$Trait = $column_family->get($Key);
		if($visitors[$i]=="111111111"){
			$v1_Cassandra_output = "<b>Cassandra: </b>".$visitors[$i]."  -  <b>BT Trait: </b>".$Trait['bt_tag_data']."<br>"; 
		}
		else if($visitors[$i]=="222222222"){
			$v2_Cassandra_output = "<b>Cassandra: </b>".$visitors[$i]."  -  <b>BT Trait: </b>".$Trait['bt_tag_data']."<br>"; 
		}
		else if($visitors[$i]=="333333333"){
			$v3_Cassandra_output = "<b>Cassandra: </b>".$visitors[$i]."  -  <b>BT Trait: </b>".$Trait['bt_tag_data']."<br>"; 
		}
		else if($visitors[$i]=="444444444"){
			$v4_Cassandra_output = "<b>Cassandra: </b>".$visitors[$i]."  -  <b>BT Trait: </b>".$Trait['bt_tag_data']."<br>"; 
		}
		else if($visitors[$i]=="555555555"){
			$v5_Cassandra_output = "<b>Cassandra: </b>".$visitors[$i]."  -  <b>BT Trait: </b>".$Trait['bt_tag_data']."<br>"; 
		}
		else if($visitors[$i]=="666666666"){
			$v6_Cassandra_output = "<b>Cassandra: </b>".$visitors[$i]."  -  <b>BT Trait: </b>".$Trait['bt_tag_data']."<br>"; 
		}
		else if($visitors[$i]=="777777777"){
			$v7_Cassandra_output = "<b>Cassandra: </b>".$visitors[$i]."  -  <b>BT Trait: </b>".$Trait['bt_tag_data']."<br>"; 
		}
	} catch (cassandra_NotFoundException $nfe) {
		if($visitors[$i]=="111111111"){
			$v1_Cassandra_output = $v1_Cassandra_output."<b>Cassandra: </b>".$visitors[$i]."  -  <b>BT Trait: </b> NOT FOUND<br>";
		}
		else if($visitors[$i]=="222222222"){
			$v2_Cassandra_output = $v2_Cassandra_output."<b>Cassandra: </b>".$visitors[$i]."  -  <b>BT Trait: </b> NOT FOUND<br>";
		}
		else if($visitors[$i]=="333333333"){
			$v3_Cassandra_output = $v3_Cassandra_output."<b>Cassandra: </b>".$visitors[$i]."  -  <b>BT Trait: </b> NOT FOUND<br>";
		}
		else if($visitors[$i]=="444444444"){
			$v4_Cassandra_output = $v4_Cassandra_output."<b>Cassandra: </b>".$visitors[$i]."  -  <b>BT Trait: </b> NOT FOUND<br>";
		}
		else if($visitors[$i]=="555555555"){
			$v5_Cassandra_output = $v5_Cassandra_output."<b>Cassandra: </b>".$visitors[$i]."  -  <b>BT Trait: </b> NOT FOUND<br>";
		}
		else if($visitors[$i]=="666666666"){
			$v6_Cassandra_output = $v6_Cassandra_output."<b>Cassandra: </b>".$visitors[$i]."  -  <b>BT Trait: </b> NOT FOUND<br>";
		}
		else if($visitors[$i]=="777777777"){
			$v7_Cassandra_output = $v7_Cassandra_output."<b>Cassandra: </b>".$visitors[$i]."  -  <b>BT Trait: </b> NOT FOUND<br>";
		}
	}
	$i++;
}

$datestamp = date("Y-m-d");
$testtime = strtotime ($datestamp);
$testtime1 = $testtime - ((86400)*1);
$datestamp1 = date("Y-m-d",$testtime1);
$testtime3 = $testtime - ((86400)*3);
$datestamp3 = date("Y-m-d",$testtime3);
$testtime4 = $testtime - ((86400)*4);
$datestamp4 = date("Y-m-d",$testtime4);
$testtime7 = $testtime - ((86400)*7);
$datestamp7 = date("Y-m-d",$testtime7);
$testtime14 = $testtime - ((86400)*14);
$datestamp14 = date("Y-m-d",$testtime14);
$day_of_the_week = date('l', $testtime);
$full_date = date('l, F j, Y', $testtime);

$expected = array (
    "Monday"    => array("1" => "4 - low",   "2" => "9 - high",  "3" => "4 - low",   "4" => "9 - high",  "5" => "21 - high", "6" => "7 - low", "7" => "2 - none"),
    "Tuesday"   => array("1" => "6 - medium","2" => "6 - medium","3" => "7 - medium","4" => "6 - medium","5" => "21 - high", "6" => "7 - low", "7" => "2 - none"),
    "Wednesday" => array("1" => "9 - high",  "2" => "3- low",    "3" => "9- high",   "4" => "4 - low",   "5" => "21 - high", "6" => "7 - low", "7" => "2 - none"),
    "Thursday"  => array("1" => "6 - medium","2" => "1 - none",  "3" => "9 - high",  "4" => "1 - none",  "5" => "21 - high", "6" => "7 - low", "7" => "2 - none"),
    "Friday"    => array("1" => "3 - low",   "2" => "1 - none",  "3" => "6 - medium","4" => "4 - low",   "5" => "21 - high", "6" => "7 - low", "7" => "2 - none"),
    "Saturday"  => array("1" => "1 - none",  "2" => "4 - low",   "3" => "4 - low",   "4" => "7 - medium","5" => "21 - high", "6" => "7 - low", "7" => "2 - none"),
    "Sunday"    => array("1" => "1 - none",  "2" => "6 - medium","3" => "1 - none",  "4" => "9 - high",  "5" => "21 - high", "6" => "7 - low", "7" => "2 - none")
);
// Username, password and schema for the database connection.
$username="aimatch";
$password="RMSAdmin";
$database="canary";

// Connect to the database and run the query
mysql_connect('w19',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

// Retrieve Current Numbers from the database
$query1 = "select sum(served) from bigsum where date<=\"".$datestamp1."\" and date >=\"".$datestamp3."\" and site=3 and area=11 and flight_creative_id=81 ";
$query11 = "select date, sites.name as sitename, areas.name as areaname, flight_creative_id, served ";
$query11 = $query11."from bigsum, sites, areas ";
$query11 = $query11."where bigsum.site = sites.id ";
$query11 = $query11."and bigsum.area = areas.id ";
$query11 = $query11."and date<=\"".$datestamp1."\" and date >=\"".$datestamp3."\" ";
$query11 = $query11."and site=3 and area=11 and flight_creative_id=81 ";
$query2 = "select sum(served) from bigsum where date<=\"".$datestamp1."\" and date >=\"".$datestamp3."\" and site=4 and area=12 and flight_creative_id=82 ";
$query22 = "select date, sites.name as sitename, areas.name as areaname, flight_creative_id, served ";
$query22 = $query22."from bigsum, sites, areas ";
$query22 = $query22."where bigsum.site = sites.id ";
$query22 = $query22."and bigsum.area = areas.id ";
$query22 = $query22."and date<=\"".$datestamp1."\" and date >=\"".$datestamp3."\" ";
$query22 = $query22."and site=4 and area=12 and flight_creative_id=82 ";
$query3 = "select sum(served) from bigsum where date<=\"".$datestamp1."\" and date >=\"".$datestamp4."\" and site=5 and area=13 and flight_creative_id=83 ";
$query33 = "select date, sites.name as sitename, areas.name as areaname, flight_creative_id, served ";
$query33 = $query33."from bigsum, sites, areas ";
$query33 = $query33."where bigsum.site = sites.id ";
$query33 = $query33."and bigsum.area = areas.id ";
$query33 = $query33."and date<=\"".$datestamp1."\" and date >=\"".$datestamp4."\" ";
$query33 = $query33."and site=5 and area=13 and flight_creative_id=83 ";
$query4 = "select sum(served) from bigsum where date<=\"".$datestamp1."\" and date >=\"".$datestamp4."\" and site=6 and area=14 and flight_creative_id=84 ";
$query44 = "select date, sites.name as sitename, areas.name as areaname, flight_creative_id, served ";
$query44 = $query44."from bigsum, sites, areas ";
$query44 = $query44."where bigsum.site = sites.id ";
$query44 = $query44."and bigsum.area = areas.id ";
$query44 = $query44."and date<=\"".$datestamp1."\" and date >=\"".$datestamp4."\" ";
$query44 = $query44."and site=6 and area=14 and flight_creative_id=84 ";
$query5 = "select sum(served) from bigsum where date<=\"".$datestamp1."\" and date >=\"".$datestamp7."\" and site=7 and area=15 and flight_creative_id=85 ";
$query55 = "select date, sites.name as sitename, areas.name as areaname, flight_creative_id, served ";
$query55 = $query55."from bigsum, sites, areas ";
$query55 = $query55."where bigsum.site = sites.id ";
$query55 = $query55."and bigsum.area = areas.id ";
$query55 = $query55."and date<=\"".$datestamp1."\" and date >=\"".$datestamp7."\" ";
$query55 = $query55."and site=7 and area=15 and flight_creative_id=85 ";
$query6 = "select sum(served) from bigsum where date<=\"".$datestamp1."\" and date >=\"".$datestamp7."\" and site=8 and area=16 and flight_creative_id=86 ";
$query66 = "select date, sites.name as sitename, areas.name as areaname, flight_creative_id, served ";
$query66 = $query66."from bigsum, sites, areas ";
$query66 = $query66."where bigsum.site = sites.id ";
$query66 = $query66."and bigsum.area = areas.id ";
$query66 = $query66."and date<=\"".$datestamp1."\" and date >=\"".$datestamp7."\" ";
$query66 = $query66."and site=8 and area=16 and flight_creative_id=86 ";
$query7 = "select sum(served) from bigsum where date<=\"".$datestamp1."\" and date >=\"".$datestamp14."\" and site=9 and area=17 and flight_creative_id=87 ";
$query77 = "select date, sites.name as sitename, areas.name as areaname, flight_creative_id, served ";
$query77 = $query77."from bigsum, sites, areas ";
$query77 = $query77."where bigsum.site = sites.id ";
$query77 = $query77."and bigsum.area = areas.id ";
$query77 = $query77."and date<=\"".$datestamp1."\" and date >=\"".$datestamp14."\" ";
$query77 = $query77."and site=9 and area=17 and flight_creative_id=87 ";

$v1_db_output = "";
$v2_db_output = "";
$v3_db_output = "";
$v4_db_output = "";
$v5_db_output = "";
$v6_db_output = "";
$v7_db_output = "";

// Visitor 1
$v1_result=mysql_query($query1);
$v11_result=mysql_query($query11);
$v1_impressions=mysql_result($v1_result,0); 
while ($row = mysql_fetch_assoc($v11_result)) {
    $v1_db_output = $v1_db_output."&nbsp;&nbsp;&nbsp;".$row['date']." - ".$row['sitename']." - ".$row['areaname']." - ".$row['flight_creative_id']." - ".$row['served']."<br>"; }
if(!$v1_impressions) { $v1_impressions = 0; }
$v1_trait = trait_level($v1_impressions,1);
// Visitor 2
$v2_result=mysql_query($query2);
$v22_result=mysql_query($query22);
$v2_impressions=mysql_result($v2_result,0); 
while ($row = mysql_fetch_assoc($v22_result)) {
    $v2_db_output = $v2_db_output."&nbsp;&nbsp;&nbsp;".$row['date']." - ".$row['sitename']." - ".$row['areaname']." - ".$row['flight_creative_id']." - ".$row['served']."<br>"; }if(!$v2_impressions) { $v2_impressions = 0; }
$v2_trait = trait_level($v2_impressions,2);
// Visitor 3
$v3_result=mysql_query($query3);
$v33_result=mysql_query($query33);
$v3_impressions=mysql_result($v3_result,0); 
while ($row = mysql_fetch_assoc($v33_result)) {
    $v3_db_output = $v3_db_output."&nbsp;&nbsp;&nbsp;".$row['date']." - ".$row['sitename']." - ".$row['areaname']." - ".$row['flight_creative_id']." - ".$row['served']."<br>"; }
if(!$v3_impressions) { $v3_impressions = 0; }
$v3_trait = trait_level($v3_impressions,3);
// Visitor 4
$v4_result=mysql_query($query4);
$v44_result=mysql_query($query44);
$v4_impressions=mysql_result($v4_result,0); 
while ($row = mysql_fetch_assoc($v44_result)) {
    $v4_db_output = $v4_db_output."&nbsp;&nbsp;&nbsp;".$row['date']." - ".$row['sitename']." - ".$row['areaname']." - ".$row['flight_creative_id']." - ".$row['served']."<br>"; }
if(!$v4_impressions) { $v4_impressions = 0; }
$v4_trait = trait_level($v4_impressions,1);
// Visitor 5
$v5_result=mysql_query($query5);
$v55_result=mysql_query($query55);
$v5_impressions=mysql_result($v5_result,0); 
while ($row = mysql_fetch_assoc($v55_result)) {
    $v5_db_output = $v5_db_output."&nbsp;&nbsp;&nbsp;".$row['date']." - ".$row['sitename']." - ".$row['areaname']." - ".$row['flight_creative_id']." - ".$row['served']."<br>"; }
if(!$v5_impressions) { $v5_impressions = 0; }
$v5_trait = trait_level($v5_impressions,5);
// Visitor 6
$v6_result=mysql_query($query6);
$v66_result=mysql_query($query66);
$v6_impressions=mysql_result($v6_result,0); 
while ($row = mysql_fetch_assoc($v66_result)) {
    $v6_db_output = $v6_db_output."&nbsp;&nbsp;&nbsp;".$row['date']." - ".$row['sitename']." - ".$row['areaname']." - ".$row['flight_creative_id']." - ".$row['served']."<br>"; }
if(!$v6_impressions) { $v6_impressions = 0; }
$v6_trait = trait_level($v6_impressions,6);
// Visitor 7
$v7_result=mysql_query($query7);
$v77_result=mysql_query($query77);
$v7_impressions=mysql_result($v7_result,0); 
while ($row = mysql_fetch_assoc($v77_result)) {
    $v7_db_output = $v7_db_output."&nbsp;&nbsp;&nbsp;".$row['date']." - ".$row['sitename']." - ".$row['areaname']." - ".$row['flight_creative_id']." - ".$row['served']."<br>"; }
if(!$v7_impressions) { $v7_impressions = 0; }
$v7_trait = trait_level($v7_impressions,7);

$db_header1 = "<b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SITE&nbsp;&nbsp;&nbsp;&nbsp;AREA&nbsp;&nbsp;&nbsp;FCID&nbsp;SERVED</b><br>";
$db_header2 = "<b>&nbsp;&nbsp;&nbsp;Actual Impressions | Expected Impressions </b><br>";
$v1_db_output2 = $db_header2."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ".$v1_impressions." - ".$v1_trait." | ".$expected[$day_of_the_week][1]."<br>";
$v2_db_output2 = $db_header2."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ".$v2_impressions." - ".$v2_trait." | ".$expected[$day_of_the_week][2]."<br>";
$v3_db_output2 = $db_header2."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ".$v3_impressions." - ".$v3_trait." | ".$expected[$day_of_the_week][3]."<br>";
$v4_db_output2 = $db_header2."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ".$v4_impressions." - ".$v4_trait." | ".$expected[$day_of_the_week][4]."<br>";
$v5_db_output2 = $db_header2."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ".$v5_impressions." - ".$v5_trait." | ".$expected[$day_of_the_week][5]."<br>";
$v6_db_output2 = $db_header2."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ".$v6_impressions." - ".$v6_trait." | ".$expected[$day_of_the_week][6]."<br>";
$v7_db_output2 = $db_header2."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ".$v7_impressions." - ".$v7_trait." | ".$expected[$day_of_the_week][7]."<br>";

function trait_level($v_impressions,$visitor){

if(($visitor == 1)||($visitor == 2)){
	if($v_impressions < 2) {
		$trait = "none"; }
	if(($v_impressions >= 2)&&($v_impressions < 5)) {
		$trait = "low"; }
	if(($v_impressions >= 5)&&($v_impressions < 8)) {
		$trait = "medium"; }
	if($v_impressions >= 8) {
		$trait = "high"; }
}
else if(($visitor == 3)||($visitor == 4)){
	if($v_impressions < 2) {
		$trait = "none"; }
	if(($v_impressions >= 2)&&($v_impressions < 5)) {
		$trait = "low"; }
	if(($v_impressions >= 5)&&($v_impressions < 8)) {
		$trait = "medium"; }
	if($v_impressions >= 8) {
		$trait = "high"; }
}
else if(($visitor == 5)||($visitor == 6)){
	if($v_impressions < 6) {
		$trait = "none"; }
	if(($v_impressions >= 6)&&($v_impressions < 12)) {
		$trait = "low"; }
	if(($v_impressions >= 12)&&($v_impressions < 20)) {
		$trait = "medium"; }
	if($v_impressions >= 20) {
		$trait = "high"; }
}
else if($visitor == 7){
	if($v_impressions < 6) {
		$trait = "none"; }
	if(($v_impressions >= 6)&&($v_impressions < 12)) {
		$trait = "low"; }
	if(($v_impressions >= 12)&&($v_impressions < 20)) {
		$trait = "medium"; }
	if($v_impressions >= 20) {
		$trait = "high"; }
}

return $trait;
}

$site_area = array("1" => " 3 11", "2" => " 4 12", "3" => " 5 13", "4" => " 6 14", "5" => " 7 15", "6" => " 8 16", "7" => " 9 17");

$DateStamp = date("Y-m-d");
//echo "Datestamp: ".$DateStamp."<br>";
$TestTime = strtotime($DateStamp);
//echo "Testtime: ".$TestTime."<br>";
$i=1;
while($i<=14){
	$testtime = $TestTime - ((86400)*$i);
//	echo "testtime: ".$testtime."<br>";
	$datestamp = date("Y-m-d",$testtime);
	$datadir[$i] = "/shareddata/customer/canary/sampling/".$datestamp."/";
	$myDirectory[$i] = opendir($datadir[$i]);
	while($entryName[$i] = readdir($myDirectory[$i])) {
//		echo "File: ".$entryName[$i]."<br>";
        $dirArray[$i][] = $entryName[$i]; }
	$indexCount[$i] = count($dirArray[$i]);
//	echo "testtime[$i]: ".$testtime[$i]."<br>";
//	echo "Datestamp: ".$datestamp[$i]."<br>";
//	echo "Directory: ".$datadir[$i]."<br>";
//	echo "Num Files: ".$indexCount[$i]."<br>";
//	echo "    Files: \n"; print_r($dirArray[$i]); echo "<br>";
	$i++; }

$i=1;
$z=1;
$v1_number=0;$v1_bt_days="";
$v2_number=0;$v2_bt_days="";
$v3_number=0;$v3_bt_days="";
$v4_number=0;$v4_bt_days="";
$v5_number=0;$v5_bt_days="";
$v6_number=0;$v6_bt_days="";
$v7_number=0;$v7_bt_days="";

while($i <= 7){
	$x=0;
	$y=1;
	if(($visitors[$i] == "111111111") || ($visitors[$i] == "222222222")) {
		$z=1;
//		echo "  Visitor: ".$visitors[$i]."<br>";
		while($y <= 3){
			$x=0;
			while($x < $indexCount[$z]){
//				echo "Filename[$y][$x] - $indexCount[$z]: ".$dirArray[$y][$x]."<br>";
				$commandline[$x] = "zcat ".$datadir[$y].$dirArray[$y][$x]." | sed -e 's/ /_/g' | sed -e 's/,/ /g' | sed -e 's/,,/ /g' | awk '{print $2,$16,$11}' | grep \"".$visitors[$i].$site_area[$i]."\"  | wc -l ";
//				echo "Commandline: ".$commandline[$x]."<br>";
				$number = exec($commandline[$x]);
//				echo "Number: ".$number."<br>";
//				echo "     ".$dirArray[$y][$x].": ".$number."<br>";
				if($visitors[$i] == "111111111"){
					$v1_number = $v1_number+$number; 
					$v1_bt_days = $v1_bt_days."&nbsp;&nbsp;&nbsp;".$dirArray[$y][$x].": ".$number."<br>"; }
				else if($visitors[$i] == "222222222"){
					$v2_number = $v2_number+$number; 
					$v2_bt_days = $v2_bt_days."&nbsp;&nbsp;&nbsp;".$dirArray[$y][$x].": ".$number."<br>"; }
				$x++;
			}
		$y++;
		$z++;
		}
	}
	else if(($visitors[$i] == "333333333") || ($visitors[$i] == "444444444")) {
		$z=1;
//		echo "  Visitor: ".$visitors[$i]."\n";
		while($y <= 4){
			$x=0;
			while($x < $indexCount[$z]){
//				echo "Filename[$y][$x] - $indexCount[$z]: ".$dirArray[$y][$x]."\n";
				$commandline[$x] = "zcat ".$datadir[$y].$dirArray[$y][$x]." | sed -e 's/ /_/g' | sed -e 's/,/ /g' | sed -e 's/,,/ /g' | awk '{print $2,$16,$11}' | grep \"".$visitors[$i].$site_area[$i]."\"  | wc -l ";
//				echo "Commandline: ".$commandline[$x]."\n";
				$number = exec($commandline[$x]);
//				echo "Number: ".$number."\n";
//				echo "     ".$dirArray[$y][$x].": ".$number."\n";
				if($visitors[$i] == "333333333"){
					$v3_number = $v3_number+$number; 
					$v3_bt_days = $v3_bt_days."&nbsp;&nbsp;&nbsp;".$dirArray[$y][$x].": ".$number."<br>"; }
				else if($visitors[$i] == "444444444"){
					$v4_number = $v4_number+$number; 
					$v4_bt_days = $v4_bt_days."&nbsp;&nbsp;&nbsp;".$dirArray[$y][$x].": ".$number."<br>"; }
				$x++;
			}
		$y++;
		$z++;
		}
	}
	else if(($visitors[$i] == "555555555") || ($visitors[$i] == "666666666")) {
		$z=1;
//		echo "  Visitor: ".$visitors[$i]."\n";
		while($y <= 7){
			$x=0;
			$bt_days = "";
			while($x < $indexCount[$z]){
//				echo "Filename[$y][$x] - $indexCount[$z]: ".$dirArray[$y][$x]."\n";
				$commandline[$x] = "zcat ".$datadir[$y].$dirArray[$y][$x]." | sed -e 's/ /_/g' | sed -e 's/,/ /g' | sed -e 's/,,/ /g' | awk '{print $2,$16,$11}' | grep \"".$visitors[$i].$site_area[$i]."\"  | wc -l ";
//				echo "Commandline: ".$commandline[$x]."\n";
				$number = exec($commandline[$x]);
//				echo "Number: ".$number."\n";
				if($visitors[$i] == "555555555"){
					$v5_number = $v5_number+$number; 
					$v5_bt_days = $v5_bt_days."&nbsp;&nbsp;&nbsp;".$dirArray[$y][$x].": ".$number."<br>"; }
				else if($visitors[$i] == "666666666"){
					$v6_number = $v6_number+$number; 
					$v6_bt_days = $v6_bt_days."&nbsp;&nbsp;&nbsp;".$dirArray[$y][$x].": ".$number."<br>"; }
				$x++;
			}
		$y++;
		$z++;
		}
	}
	else if($visitors[$i] == "777777777") {
		$z=1;
//		echo "  Visitor: ".$visitors[$i]."\n";
		while($y <= 14){
			$x=0;
			while($x < $indexCount[$z]){
//				echo "Filename[$y][$x] - $indexCount[$z]: ".$dirArray[$y][$x]."\n";
				$commandline[$x] = "zcat ".$datadir[$y].$dirArray[$y][$x]." | sed -e 's/ /_/g' | sed -e 's/,/ /g' | sed -e 's/,,/ /g' | awk '{print $2,$16,$11}' | grep \"".$visitors[$i].$site_area[$i]."\"  | wc -l ";
//				echo "Commandline: ".$commandline[$x]."\n";
				$number = exec($commandline[$x]);
//				echo "Number: ".$number."\n";
				$v7_bt_days = $v7_bt_days."&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$dirArray[$y][$x].": ".$number."<br>";
				$v7_number = $v7_number+$number; 
				$x++;
			}
		$y++;
		$z++;
		}
	}

	
$i++;
}
		$v1_log = "&nbsp;&nbsp;&nbsp;Visitor 1: Registered ".$v1_number." impressions that matched SITE.ID=3 and AREA.ID=11 over the last 3 days.<br>";
		if($v1_number < 2){
			$v1_log = $v1_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be NONE<br>"; }
		else if (($v1_number >= 2)&&($v1_number < 5)){
			$v1_log = $v1_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be LOW<br>"; }
		else if (($v1_number >= 5)&&($v1_number < 8)){
			$v1_log = $v1_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be MEDIUM<br>"; }
		else if ($v1_number >= 8){
			$v1_log = $v1_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be HIGH<br>"; }

		$v2_log = "&nbsp;&nbsp;&nbsp;Visitor 2: Registered ".$v2_number." impressions that matched SITE.ID=4 and AREA.ID=12 over the last 3 days.<br>";
		if($v2_number < 2){
			$v2_log = $v2_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be NONE<br>"; }
		else if (($v2_number >= 2)&&($v2_number < 5)){
			$v2_log = $v2_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be LOW<br>"; }
		else if (($v2_number >= 5)&&($v2_number < 8)){
			$v2_log = $v2_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be MEDIUM<br>"; }
		else if ($v2_number >= 8){
			$v2_log = $v2_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be HIGH<br>"; }

		$v3_log = "&nbsp;&nbsp;&nbsp;Visitor 3: Registered ".$v3_number." impressions that matched SITE.ID=5 and AREA.ID=13 over the last 4 days.<br>";
		if($v3_number < 2){
			$v3_log = $v3_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be NONE<br>"; }
		else if (($v3_number >= 2)&&($v3_number < 5)){
			$v3_log = $v3_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be LOW<br>"; }
		else if (($v3_number >= 5)&&($v3_number < 8)){
			$v3_log = $v3_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be MEDIUM<br>"; }
		else if ($v3_number >= 8){
			$v3_log = $v3_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be HIGH<br>"; }

		$v4_log = "&nbsp;&nbsp;&nbsp;Visitor 4: Registered ".$v4_number." impressions that matched SITE.ID=6 and AREA.ID=14 over the last 4 days.<br>";
		if($v4_number < 2){
			$v4_log = $v4_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be NONE<br>"; }
		else if (($v4_number >= 2)&&($v4_number < 5)){
			$v4_log = $v4_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be LOW<br>"; }
		else if (($v4_number >= 5)&&($v4_number < 8)){
			$v4_log = $v4_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be MEDIUM<br>"; }
		else if ($v4_number >= 8){
			$v4_log = $v4_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be HIGH<br>"; }

		$v5_log = "&nbsp;&nbsp;&nbsp;Visitor 5: Registered ".$v5_number." impressions that matched SITE.ID=7 and AREA.ID=15 over the last 7 days.<br>";
		if($v5_number < 6){
			$v5_log = $v5_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be NONE<br>"; }
		else if (($v5_number >= 6)&&($v5_number < 12)){
			$v5_log = $v5_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be LOW<br>"; }
		else if (($v5_number >= 12)&&($v5_number < 20)){
			$v5_log = $v5_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be MEDIUM<br>"; }
		else if ($v5_number >= 20){
			$v5_log = $v5_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be HIGH<br>"; }

		$v6_log = "&nbsp;&nbsp;&nbsp;Visitor 6: Registered ".$v6_number." impressions that matched SITE.ID=8 and AREA.ID=16 over the last 7 days.<br>";
		if($v6_number < 6){
			$v6_log = $v6_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be NONE<br>"; }
		else if (($v6_number >= 6)&&($v6_number < 12)){
			$v6_log = $v6_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be LOW<br>"; }
		else if (($v6_number >= 12)&&($v6_number < 20)){
			$v6_log = $v6_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be MEDIUM<br>"; }
		else if ($v6_number >= 20){
			$v6_log = $v6_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be HIGH<br>"; }

		$v7_log = "&nbsp;&nbsp;&nbsp;Visitor 7: Registered ".$v7_number." impressions that matched SITE.ID=9 and AREA.ID=17 over the last 14 days.<br>";
		if($v7_number < 6){
			$v7_log = $v7_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be NONE<br>"; }
		else if (($v7_number >= 6)&&($v7_number < 12)){
			$v7_log = $v7_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be LOW<br>"; }
		else if (($v7_number >= 12)&&($v7_number < 20)){
			$v7_log = $v7_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be MEDIUM<br>"; }
		else if ($v7_number >= 20){
			$v7_log = $v7_log."&nbsp;&nbsp;&nbsp;The trait for this visitor should be HIGH<br>"; }

	$url1 = "http://crtldev.aimatch.com:60000/canary/hserver/mid=111111111/size=468x60/trace=1";
	$output1 = MakeAdCall($url1,'',$debug);
	$output_array1 = MakeOutputArray($output1,$debug);
	$response1 = parseResponse($output_array1,">>>> Selected",$debug);

	$url2 = "http://crtldev.aimatch.com:60000/canary/hserver/mid=222222222/size=468x60/trace=1";
	$output2 = MakeAdCall($url2,'',$debug);
	$output_array2 = MakeOutputArray($output2,$debug);
	$response2 = parseResponse($output_array2,">>>> Selected",$debug);

	$url3 = "http://crtldev.aimatch.com:60000/canary/hserver/mid=333333333/size=468x60/trace=1";
	$output3 = MakeAdCall($url3,'',$debug);
	$output_array3 = MakeOutputArray($output3,$debug);
	$response3 = parseResponse($output_array3,">>>> Selected",$debug);

	$url4 = "http://crtldev.aimatch.com:60000/canary/hserver/mid=444444444/size=468x60/trace=1";
	$output4 = MakeAdCall($url4,'',$debug);
	$output_array4 = MakeOutputArray($output4,$debug);
	$response4 = parseResponse($output_array4,">>>> Selected",$debug);

	$url5 = "http://crtldev.aimatch.com:60000/canary/hserver/mid=555555555/size=468x60/trace=1";
	$output5 = MakeAdCall($url5,'',$debug);
	$output_array5 = MakeOutputArray($output5,$debug);
	$response5 = parseResponse($output_array5,">>>> Selected",$debug);

	$url6 = "http://crtldev.aimatch.com:60000/canary/hserver/mid=666666666/size=468x60/trace=1";
	$output6 = MakeAdCall($url6,'',$debug);
	$output_array6 = MakeOutputArray($output6,$debug);
	$response6 = parseResponse($output_array6,">>>> Selected",$debug);

	$url7 = "http://crtldev.aimatch.com:60000/canary/hserver/mid=777777777/size=468x60/trace=1";
	$output7 = MakeAdCall($url7,'',$debug);
	$output_array7 = MakeOutputArray($output7,$debug);
	$response7 = parseResponse($output_array7,">>>> Selected",$debug);
	
			
$contents1 = getFileContents(1);
$contents2 = getFileContents(2);
$contents3 = getFileContents(3);
$contents4 = getFileContents(4);
$contents5 = getFileContents(5);
$contents6 = getFileContents(6);
$contents7 = getFileContents(7);
$days1 = 86400*1;
$days2 = 86400*2;
$days3 = 86400*3;
$days4 = 86400*4;
$days5 = 86400*5;
$days6 = 86400*6;
$days7 = 86400*7;
echo "<font face=\"courier\">";
echo "<b>BT Debugging Information for: </b>".$full_date."<br><br>";
// - Visitor 1
echo "<hr>";
echo "<b>Visitor GUID: 111111111</b> - Trait Period is three days<br>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days1).": </b><br><pre>".getAdCalls(1,$contents1)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days2).": </b><br><pre>".getAdCalls(1,$contents2)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days3).": </b><br><pre>".getAdCalls(1,$contents3)."</pre><br>";
echo $v1_Cassandra_output;
echo "<br><b>Campaigns logging details in the database:</b><br>";
echo $db_header1;
echo $v1_db_output;
echo $v1_db_output2;
echo "<br><b>Sequencer Log Files for Visitor 111111111</b><br>";
echo $v1_bt_days;
echo "<br><b>&nbsp;&nbsp;&nbsp;Trait Levels are: </b> 0=none,2=low,5=medium,8=high<br>";
echo $v1_log;
echo "<br><b>AdCall: </b>".$url1."<br>";
echo "<b>AdCall Response: </b>".$response1."<br><br>";
echo expectedResultsTable(1);
echo "<hr>";
echo "<b>Visitor GUID: 222222222</b> - Trait Period is three days<br>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days1).": </b><br><pre>".getAdCalls(2,$contents1)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days2).": </b><br><pre>".getAdCalls(2,$contents2)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days3).": </b><br><pre>".getAdCalls(2,$contents3)."</pre><br>";
echo $v2_Cassandra_output;
echo $db_header1;
echo $v2_db_output;
echo $v2_db_output2;
echo "<br><b>Sequencer Log Files for Visitor 222222222</b><br>";
echo $v2_bt_days;
echo "<br><b>&nbsp;&nbsp;&nbsp;Trait Levels are: </b> 0=none,2=low,5=medium,8=high<br>";
echo $v2_log;
echo "<br><b>AdCall: </b>".$url2."<br>";
echo "<b>AdCall Response: </b>".$response2."<br><br>";
echo expectedResultsTable(2);
echo "<hr>";
echo "<b>Visitor GUID: 333333333</b> - Trait Period is four days<br>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days1).": </b><br><pre>".getAdCalls(3,$contents1)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days2).": </b><br><pre>".getAdCalls(3,$contents2)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days3).": </b><br><pre>".getAdCalls(3,$contents3)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days4).": </b><br><pre>".getAdCalls(3,$contents4)."</pre><br>";
echo $v3_Cassandra_output;
echo $db_header1;
echo $v3_db_output;
echo $v3_db_output2;
echo "<br><b>Sequencer Log Files for Visitor 333333333</b><br>";
echo $v3_bt_days;
echo "<br><b>&nbsp;&nbsp;&nbsp;Trait Levels are: </b> 0=none,2=low,5=medium,8=high<br>";
echo $v3_log;
echo "<br><b>AdCall: </b>".$url3."<br>";
echo "<b>AdCall Response: </b>".$response3."<br><br>";
echo expectedResultsTable(3);
echo "<hr>";
echo "<b>Visitor GUID: 444444444</b> - Trait Period is four days<br>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days1).": </b><br><pre>".getAdCalls(4,$contents1)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days2).": </b><br><pre>".getAdCalls(4,$contents2)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days3).": </b><br><pre>".getAdCalls(4,$contents3)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days4).": </b><br><pre>".getAdCalls(4,$contents4)."</pre><br>";
echo $v4_Cassandra_output;
echo $db_header1;
echo $v4_db_output;
echo $v4_db_output2;
echo "<br><b>Sequencer Log Files for Visitor 444444444</b><br>";
echo $v4_bt_days;
echo "<br><b>&nbsp;&nbsp;&nbsp;Trait Levels are: </b> 0=none,2=low,5=medium,8=high<br>";
echo $v4_log;
echo "<br><b>AdCall: </b>".$url4."<br>";
echo "<b>AdCall Response: </b>".$response4."<br><br>";
echo expectedResultsTable(4);
echo "<hr>";
echo "<b>Visitor GUID: 555555555</b> - Trait Period is seven days<br>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days1).": </b><br><pre>".getAdCalls(5,$contents1)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days2).": </b><br><pre>".getAdCalls(5,$contents2)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days3).": </b><br><pre>".getAdCalls(5,$contents3)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days4).": </b><br><pre>".getAdCalls(5,$contents4)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days5).": </b><br><pre>".getAdCalls(5,$contents5)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days6).": </b><br><pre>".getAdCalls(5,$contents6)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days7).": </b><br><pre>".getAdCalls(5,$contents7)."</pre><br>";
echo $v5_Cassandra_output;
echo $db_header1;
echo $v5_db_output;
echo $v5_db_output2;
echo "<br><b>Sequencer Log Files for Visitor 555555555</b><br>";
echo $v5_bt_days;
echo "<br><b>&nbsp;&nbsp;&nbsp;Trait Levels are: </b> 0=none,7=low,12=medium,20=high<br>";
echo $v5_log;
echo "<br><b>AdCall: </b>".$url5."<br>";
echo "<b>AdCall Response: </b>".$response5."<br><br>";
echo expectedResultsTable(5);
echo "<hr>";
echo "<b>Visitor GUID: 666666666</b> - Trait Period is seven days<br>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days1).": </b><br><pre>".getAdCalls(6,$contents1)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days2).": </b><br><pre>".getAdCalls(6,$contents2)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days3).": </b><br><pre>".getAdCalls(6,$contents3)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days4).": </b><br><pre>".getAdCalls(6,$contents4)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days5).": </b><br><pre>".getAdCalls(6,$contents5)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days6).": </b><br><pre>".getAdCalls(6,$contents6)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days7).": </b><br><pre>".getAdCalls(6,$contents7)."</pre><br>";
echo $v6_Cassandra_output;
echo $db_header1;
echo $v6_db_output;
echo $v6_db_output2;
echo "<br><b>Sequencer Log Files for Visitor 666666666</b><br>";
echo $v6_bt_days;
echo "<br><b>&nbsp;&nbsp;&nbsp;Trait Levels are: </b> 0=none,7=low,12=medium,20=high<br>";
echo $v6_log;
echo "<br><b>AdCall: </b>".$url6."<br>";
echo "<b>AdCall Response: </b>".$response6."<br><br>";
echo expectedResultsTable(6);
echo "<hr>";
echo "<b>Visitor GUID: 777777777</b> - Trait Period is fourteen days<br>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days1).": </b><br><pre>".getAdCalls(7,$contents1)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days2).": </b><br><pre>".getAdCalls(7,$contents2)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days3).": </b><br><pre>".getAdCalls(7,$contents3)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days4).": </b><br><pre>".getAdCalls(7,$contents4)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days5).": </b><br><pre>".getAdCalls(7,$contents5)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days6).": </b><br><pre>".getAdCalls(7,$contents6)."</pre>";
echo "<br><b>Ad Calls Made on ".date('l',$testtime-$days7).": </b><br><pre>".getAdCalls(7,$contents7)."</pre><br>";
echo $v7_Cassandra_output;
echo $db_header1;
echo $v7_db_output;
echo $v7_db_output2;
echo "<br><b>Sequencer Log Files for Visitor 777777777</b><br>";
echo $v7_bt_days;
echo "<br><b>&nbsp;&nbsp;&nbsp;Trait Levels are: </b> 0=none,7=low,12=medium,20=high<br>";
echo $v7_log;
echo "<br><b>AdCall: </b>".$url7."<br>";
echo "<b>AdCall Response: </b>".$response7."<br><br>";
echo expectedResultsTable(7);
echo "</font>";

function MakeAdCall($url,$cookiefile,$debug) {
	$UserAgent="Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.16) Gecko/20110319 Firefox/3.6.16";

    if (isset($debug)) { echo "URL: ".$url."<br>"; }

    // initilize the curl call
    $ch = curl_init();
    // set useragent
    curl_setopt($ch, CURLOPT_USERAGENT, $UserAgent);
	// Read Cookies from Cookiefile
	curl_setopt ($ch, CURLOPT_COOKIEFILE, '/http/matchtest/tests/cookiefile.txt'); 
    // Set curl to use $url for http call
    curl_setopt($ch, CURLOPT_URL, $url);
    // show client headers
    curl_setopt($ch, CURLOPT_HEADER, 1);
    // have curl put X-Forwarded-For into headers
    curl_setopt($ch,CURLOPT_HTTPHEADER, $client_headers);
    // store results as the return of curl_exec
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    // Follow redirects
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);		
    // if HTML error 400 over over, fail
    curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
	// Save Cookies in Cookiefile
	curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookiefile); 

    $output = curl_exec($ch);
    if (isset($debug)) { echo "HTTP Response Output:<br><pre>"; print_r($output); echo "</pre><br>"; }
    //close curl connection
    curl_close($ch);

return $output;
}


function MakeOutputArray($output,$debug){
        $output_array = preg_split('/[\n]/', $output, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
        if (isset($debug)) { echo "HTTP Response Output (array):<br><pre>"; print_r($output_array); echo "</pre><br><br>"; }

return $output_array;
}


function parseResponse($output_array,$string,$debug) {
		$i=0;
        $num = count($output_array);
		while($i <= $num){
			if(stripos($output_array[$i],$string)){
				return $output_array[$i];
			}
		$i++;
		}
}

function expectedResultsTable($visitor){
	if($visitor == 1){
		$tableHeader = "<table border=\"1\"><tr><th>&nbsp;Visitor 1</th><th>&nbsp;Sunday&nbsp;</th><th>&nbsp;Monday&nbsp;</th><th>&nbsp;Tuesday&nbsp;</th><th>&nbsp;Wednesday&nbsp;</th><th>&nbsp;Thursday&nbsp;</th><th>&nbsp;Friday&nbsp;</th><th>&nbsp;Saturday&nbsp;</th></tr>";
		$tableBody = "<tr align=\"center\"><td align=\"left\">&nbsp;Impressions Logged</td><td>3</td><td>3</td><td>3</td><td>0</td><td>0</td><td>1</td><td>0</td></tr>";
		$tableBody = $tableBody."<tr align=\"center\"><td align=\"left\">&nbsp;Traits Present</td><td>1</td><td>4</td><td>6</td><td>9</td><td>6</td><td>3</td><td>1</td></tr>";
		$tableBody = $tableBody."<tr align=\"center\"><td align=\"left\">&nbsp;Expected BT Behavior&nbsp;</td><td>NONE</td><td>LOW</td><td>MEDIUM</td><td>HIGH</td><td>MEDIUM</td><td>LOW</td><td>NONE</td></tr>";
		$tableFooter = "</table><br>"; }
	else if($visitor == 2){
		$tableHeader = "<table border=\"1\"><tr><th>&nbsp;Visitor 2</th><th>&nbsp;Sunday&nbsp;</th><th>&nbsp;Monday&nbsp;</th><th>&nbsp;Tuesday&nbsp;</th><th>&nbsp;Wednesday&nbsp;</th><th>&nbsp;Thursday&nbsp;</th><th>&nbsp;Friday&nbsp;</th><th>&nbsp;Saturday&nbsp;</th></tr>";
		$tableBody = "<tr align=\"center\"><td align=\"left\">&nbsp;Impressions Logged</td><td>3</td><td>0</td><td>0</td><td>1</td><td>0</td><td>3</td><td>3</td></tr>";
		$tableBody = $tableBody."<tr align=\"center\"><td align=\"left\">&nbsp;Traits Present</td><td>6</td><td>9</td><td>6</td><td>3</td><td>1</td><td>1</td><td>4</td></tr>";
		$tableBody = $tableBody."<tr align=\"center\"><td align=\"left\">&nbsp;Expected BT Behavior&nbsp;</td><td>MEDIUM</td><td>HIGH</td><td>MEDIUM</td><td>LOW</td><td>NONE</td><td>NONE</td><td>LOW</td></tr>";
		$tableFooter = "</table><br>"; }
	else if($visitor == 3){
		$tableHeader = "<table border=\"1\"><tr><th>&nbsp;Visitor 3</th><th>&nbsp;Sunday&nbsp;</th><th>&nbsp;Monday&nbsp;</th><th>&nbsp;Tuesday&nbsp;</th><th>&nbsp;Wednesday&nbsp;</th><th>&nbsp;Thursday&nbsp;</th><th>&nbsp;Friday&nbsp;</th><th>&nbsp;Saturday&nbsp;</th></tr>";
		$tableBody = "<tr align=\"center\"><td align=\"left\">&nbsp;Impressions Logged</td><td>3</td><td>3</td><td>3</td><td>0</td><td>0</td><td>1</td><td>0</td></tr>";
		$tableBody = $tableBody."<tr align=\"center\"><td align=\"left\">&nbsp;Traits Present</td><td>1</td><td>4</td><td>7</td><td>9</td><td>9</td><td>6</td><td>4</td></tr>";
		$tableBody = $tableBody."<tr align=\"center\"><td align=\"left\">&nbsp;Expected BT Behavior&nbsp;</td><td>NONE</td><td>LOW</td><td>MEDIUM</td><td>HIGH</td><td>HIGH</td><td>MEDIUM</td><td>LOW</td></tr>";
		$tableFooter = "</table><br>"; }
	else if($visitor == 4){
		$tableHeader = "<table border=\"1\"><tr><th>&nbsp;Visitor 4</th><th>&nbsp;Sunday&nbsp;</th><th>&nbsp;Monday&nbsp;</th><th>&nbsp;Tuesday&nbsp;</th><th>&nbsp;Wednesday&nbsp;</th><th>&nbsp;Thursday&nbsp;</th><th>&nbsp;Friday&nbsp;</th><th>&nbsp;Saturday&nbsp;</th></tr>";
		$tableBody = "<tr align=\"center\"><td align=\"left\">&nbsp;Impressions Logged</td><td>0</td><td>0</td><td>1</td><td>0</td><td>3</td><td>3</td><td>3</td></tr>";
		$tableBody = $tableBody."<tr align=\"center\"><td align=\"left\">&nbsp;Traits Present</td><td>9</td><td>9</td><td>6</td><td>4</td><td>1</td><td>4</td><td>7</td></tr>";
		$tableBody = $tableBody."<tr align=\"center\"><td align=\"left\">&nbsp;Expected BT Behavior&nbsp;</td><td>HIGH</td><td>HIGH</td><td>MEDIUM</td><td>LOW</td><td>NONE</td><td>LOW</td><td>MEDIUM</td></tr>";
		$tableFooter = "</table><br>"; }
	else if($visitor == 5){
		$tableHeader = "<table border=\"1\"><tr><th>&nbsp;Visitor 5</th><th>&nbsp;Sunday&nbsp;</th><th>&nbsp;Monday&nbsp;</th><th>&nbsp;Tuesday&nbsp;</th><th>&nbsp;Wednesday&nbsp;</th><th>&nbsp;Thursday&nbsp;</th><th>&nbsp;Friday&nbsp;</th><th>&nbsp;Saturday&nbsp;</th></tr>";
		$tableBody = "<tr align=\"center\"><td align=\"left\">&nbsp;Impressions Logged</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td><td>3</td></tr>";
		$tableBody = $tableBody."<tr align=\"center\"><td align=\"left\">&nbsp;Traits Present</td><td>21</td><td>21</td><td>21</td><td>21</td><td>21</td><td>21</td><td>21</td></tr>";
		$tableBody = $tableBody."<tr align=\"center\"><td align=\"left\">&nbsp;Expected BT Behavior&nbsp;</td><td>HIGH</td><td>HIGH</td><td>HIGH</td><td>HIGH</td><td>HIGH</td><td>HIGH</td><td>HIGH</td></tr>";
		$tableFooter = "</table><br>"; }
	else if($visitor == 6){
		$tableHeader = "<table border=\"1\"><tr><th>&nbsp;Visitor 6</th><th>&nbsp;Sunday&nbsp;</th><th>&nbsp;Monday&nbsp;</th><th>&nbsp;Tuesday&nbsp;</th><th>&nbsp;Wednesday&nbsp;</th><th>&nbsp;Thursday&nbsp;</th><th>&nbsp;Friday&nbsp;</th><th>&nbsp;Saturday&nbsp;</th></tr>";
		$tableBody = "<tr align=\"center\"><td align=\"left\">&nbsp;Impressions Logged</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td><td>1</td></tr>";
		$tableBody = $tableBody."<tr align=\"center\"><td align=\"left\">&nbsp;Traits Present</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td><td>7</td></tr>";
		$tableBody = $tableBody."<tr align=\"center\"><td align=\"left\">&nbsp;Expected BT Behavior&nbsp;</td><td>LOW</td><td>LOW</td><td>LOW</td><td>LOW</td><td>LOW</td><td>LOW</td><td>LOW</td></tr>";
		$tableFooter = "</table><br>"; }
	else if($visitor == 7){
		$tableHeader = "<table border=\"1\"><tr><th>&nbsp;Visitor 7</th><th>&nbsp;Sunday&nbsp;</th><th>&nbsp;Monday&nbsp;</th><th>&nbsp;Tuesday&nbsp;</th><th>&nbsp;Wednesday&nbsp;</th><th>&nbsp;Thursday&nbsp;</th><th>&nbsp;Friday&nbsp;</th><th>&nbsp;Saturday&nbsp;</th></tr>";
		$tableBody = "<tr align=\"center\"><td align=\"left\">&nbsp;Impressions Logged</td><td>1</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td><td>0</td></tr>";
		$tableBody = $tableBody."<tr align=\"center\"><td align=\"left\">&nbsp;Traits Present</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td><td>2</td></tr>";
		$tableBody = $tableBody."<tr align=\"center\"><td align=\"left\">&nbsp;Expected BT Behavior&nbsp;</td><td>NONE</td><td>NONE</td><td>NONE</td><td>NONE</td><td>NONE</td><td>NONE</td><td>NONE</td></tr>";
		$tableFooter = "</table><br>"; }
	
$tableText = $tableHeader.$tableBody.$tableFooter;

return $tableText;
}

function getAdCalls($visitor,$contents){
	$start = $visitor; 
	$end = $visitor+1;
	$count = count($contents);
	$i=0;
	while($i<=$count){
//		echo "COUNT: ".$i." CONTENTS: ".$contents[$i]."<br>";
		if(substr_compare($contents[$i],"-----",0,4)==0){
			$count_dashes = $count_dashes+1; 
//			echo "FOUND DASHES at INDEX ".$i."<br>"; 
		}
		if($count_dashes == $end) {
			$begin_capture = 0; $end_capture = 1; }
		if($begin_capture == 1){
			$adcalls = $adcalls.$contents[$i]; }
		if($count_dashes == $start){
			$begin_capture = 1; }
		if($end_capture == 1){
//			$adcalls = $adcalls.$contents[$i]; 
			$end_capture = 0;}
	$i++;
	}
return $adcalls;
}

function getFileContents($days){
$datestamp = date("Y-m-d");
$testtime = strtotime ($datestamp);
$path = "/http/matchtest/tests/";
$full_date = date('l, F j, Y', $testtime);
$seconds = $days*84600;
$day = date('l', $testtime-$seconds);
$short_day = substr(strtolower($day),0,2);
$filename = "bt_traffic_".$short_day.".out";
//echo "Today's Date: ".$full_date."<br>";
//echo "Day: ".$day."<br>";
//echo "Short Day: ".$short_day."<br>";
//echo "Filename: ".$filename."<br>";
//echo "Path: ".$path.$filename."<br>";
$contents = file($path.$filename);
return $contents;
}

?>
